package com.tjresearch.redisdbtasktracker.runner;

import java.util.Date;

import java.util.Map;

import com.tjresearch.redisdbtasktracker.pojo.HfData;
import com.tjresearch.redisdbtasktracker.service.JobService;
import com.tjresearch.redisdbtasktracker.utils.DateUtils;


public class CalculateUtils {
	

	//全量三十天平均值
	public static double calAve(Date date,Map<String,HfData> map,int itemId) {
		Date tmp = null;
		double sum = 0.00;
		for(int i = 0;i<30;i++){
			tmp = DateUtils.getDayBefore(date, i);
			String key = ""+itemId+"_"+tmp.getTime();
			if(map.get(key)!=null){
				sum +=Double.parseDouble( map.get(key).getValue());
			}
		}
		return sum/30;
	}
	//增量三十天平均值
	public static double CalAddAve(int itemId,Date date ,JobService jobService){
		double sum = 0;
		//取出前30天
		Date startCalTime = DateUtils.getDayBefore(date, 29);
		sum = jobService.calRValue(itemId,date,startCalTime);
		return sum/30;
		
	}
	
}
